package com.huiminpay.merchant.controller;

import com.huiminpay.common.cache.util.SecurityUtil;
import com.huiminpay.transaction.api.dto.PayChannelDTO;
import com.huiminpay.transaction.api.dto.PayChannelParamDTO;
import com.huiminpay.transaction.api.dto.PlatformChannelDTO;
import com.huiminpay.transaction.api.service.playfromApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "平台服务渠道管理")
@Slf4j
public class PlatformChanelController {
    @Reference
    private  playfromApi playfromApi;

    @ApiOperation("获取平台服务类型(第一步查询初线上线下这些列表)")
    @GetMapping(value="/my/platform-channels")
    public List<PlatformChannelDTO> queryPlatformChannel(){
        return playfromApi.queryPlatformChannel();
    }

    @ApiOperation("绑定服务类型(第二部当用户点击按钮的时候，用户的应用要绑定到服务类型上面去)")
    @PostMapping(value="/my/apps/{appId}/platform-channels")
    @ApiImplicitParams({@ApiImplicitParam(value = "应用id",name = "appId",dataType = "string",paramType = "path"),
            @ApiImplicitParam(value = "服务类型code",name = "platformChannelCodes",dataType = "string",paramType = "query")
    })
    public void bindPlatformForApp(@PathVariable("appId") String appId, @RequestParam("platformChannelCodes") String platformChannelCodes){
        playfromApi.bindPlatformChannelForApp(appId,platformChannelCodes);
    }
    @ApiOperation("查询应用是否绑定了某个服务类型(第三部绑定之后，按钮需要显示为灰色)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", value = "应用appId", required = true, dataType =
                    "String", paramType = "query"),
            @ApiImplicitParam(name = "platformChannel", value = "服务类型", required = true, dataType =
                    "String", paramType = "query")
    })
    @GetMapping("/my/merchants/apps/platformchannels")
    public int queryAppBindPlatformChannel(@RequestParam String appId, @RequestParam String
            platformChannel){
        return playfromApi.queryAppBindPlatformChannel(appId,platformChannel);
    }
    @ApiOperation("根据平台服务类型获取支付渠道列表(4查询支付渠道列表)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "platformChannelCode", value = "服务类型编码", required =
                    true, dataType = "String", paramType = "path")
    })
    @GetMapping(value="/my/pay-channels/platform-channel/{platformChannelCode}")
    public List<PayChannelDTO> queryPayChannelByPlatformChannel(@PathVariable String platformChannelCode){
        return playfromApi.findPayChane(platformChannelCode);
    }
    @ApiOperation("商户配置支付渠道参数(5配置支付渠道参数)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "payChannelParam", value = "商户配置支付渠道参数", required =
                    true, dataType = "PayChannelParamDTO", paramType = "body")
    })
    @RequestMapping(value = "/my/pay-channel-params",method =
            {RequestMethod.POST,RequestMethod.PUT})
    public PayChannelParamDTO createPayChannelParam(@RequestBody PayChannelParamDTO payChannelParam){
        Long merchantId = SecurityUtil.getMerchantId();
        payChannelParam.setMerchantId(merchantId);
        PayChannelParamDTO payChannelParamDTO=playfromApi.savePayChannelParam(payChannelParam);
        return  payChannelParamDTO;
    }

    @ApiOperation("获取指定应用指定服务类型下所包含的原始支付渠道参数列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", value = "应用id", required = true, dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "platformChannel", value = "服务类型", required = true, dataType = "String", paramType = "path")})
    @GetMapping(value = "/my/pay-channel-params/apps/{appId}/platform-channels/{platformChannel}")
    public List<PayChannelParamDTO> queryPayChannelParam(@PathVariable String appId, @PathVariable String platformChannel) {
        return playfromApi.findPayChannerlParm(appId, platformChannel);
    }
//    @ApiOperation("配置支付参数渠道")
//    @GetMapping(value = "/my/pay-channel-params/apps/{appId}/platform-channels/{platformChannel}")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "appId", value = "应用id", dataType = "String", paramType = "path"),
//            @ApiImplicitParam(name = "platformChannel", value = "平台支付渠道",  dataType = "String", paramType = "path"),
//            @ApiImplicitParam(name = "payChannel", value = "第三方支付渠道",  dataType = "String", paramType = "path"),
//             })
//    public PayChannelParamDTO queryPayChannelParam(@PathVariable String appId,
//                                                   @PathVariable String platformChannel, @PathVariable String payChannel) {
//        return playfromApi.findPayChannerlParmA(appId, platformChannel, payChannel);

   // }


}
